/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package telas;

import usuario.UsuarioDAO;
import usuario.Usuario;
import br.edu.GenericDAO;
import java.util.List;
import javax.swing.JOptionPane;
import usuario.UsuarioModal;

/**
 *
 * @author Max Weber
 */
public class O4TelaConsultarUsuarios extends javax.swing.JDialog {

    private boolean respExcluir;
    boolean cadastrado;

    /**
     * Creates new form O4TelaConsultarUsuarios
     */
    public O4TelaConsultarUsuarios() {
        initComponents();
        UsuarioDAO dao = new UsuarioDAO();
        UsuarioModal usuarios = new UsuarioModal(dao.listar());
        tbConsultarUsuario.setModel(usuarios);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbConsultarUsuario = new javax.swing.JTable();
        jPanel7 = new javax.swing.JPanel();
        iconExcluirUsuario = new javax.swing.JLabel();
        btExcluir = new javax.swing.JLabel();
        jPanel8 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        btAlterarSenha = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        btVerPerfil = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("SISVATEC - Sistema de Vacinação");
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel2.setBackground(new java.awt.Color(10, 66, 108));
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel3.setBackground(new java.awt.Color(0, 114, 180));
        jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/users.png"))); // NOI18N
        jPanel3.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, -1, 50));

        jLabel1.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 36)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Consultar Usuários");
        jPanel3.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 20, -1, -1));

        jPanel2.add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 560, 63));

        jPanel1.add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 560, 70));

        tbConsultarUsuario.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(tbConsultarUsuario);

        jPanel1.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 90, -1, 230));

        jPanel7.setBackground(new java.awt.Color(10, 66, 108));
        jPanel7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanel7MouseClicked(evt);
            }
        });
        jPanel7.setLayout(new java.awt.GridBagLayout());

        iconExcluirUsuario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/excluir2.png"))); // NOI18N
        iconExcluirUsuario.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                iconExcluirUsuarioMouseClicked(evt);
            }
        });
        jPanel7.add(iconExcluirUsuario, new java.awt.GridBagConstraints());

        btExcluir.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        btExcluir.setForeground(new java.awt.Color(255, 255, 255));
        btExcluir.setText("  Excluir");
        btExcluir.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btExcluirMouseClicked(evt);
            }
        });
        jPanel7.add(btExcluir, new java.awt.GridBagConstraints());

        jPanel1.add(jPanel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 350, 150, 30));

        jPanel8.setBackground(new java.awt.Color(10, 66, 108));
        jPanel8.setLayout(new java.awt.GridBagLayout());

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/senha.png"))); // NOI18N
        jPanel8.add(jLabel4, new java.awt.GridBagConstraints());

        btAlterarSenha.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        btAlterarSenha.setForeground(new java.awt.Color(255, 255, 255));
        btAlterarSenha.setText(" Resetar senha");
        btAlterarSenha.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btAlterarSenhaMouseClicked(evt);
            }
        });
        jPanel8.add(btAlterarSenha, new java.awt.GridBagConstraints());

        jPanel1.add(jPanel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 350, 150, 30));

        jPanel9.setBackground(new java.awt.Color(10, 66, 108));
        jPanel9.setLayout(new java.awt.GridBagLayout());

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/perfil.png"))); // NOI18N
        jPanel9.add(jLabel5, new java.awt.GridBagConstraints());

        btVerPerfil.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        btVerPerfil.setForeground(new java.awt.Color(255, 255, 255));
        btVerPerfil.setText("  Ver perfil");
        btVerPerfil.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btVerPerfilMouseClicked(evt);
            }
        });
        jPanel9.add(btVerPerfil, new java.awt.GridBagConstraints());

        jPanel1.add(jPanel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 350, 150, 30));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 560, 400));

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    public void excluirUsuario() {
        int linha = tbConsultarUsuario.getSelectedRow();
        if (linha == -1) {
            JOptionPane.showMessageDialog(rootPane, "Por favor, selecione um usuário");
        } else {

            Usuario usuario = new Usuario();
            int codigo = (int) tbConsultarUsuario.getValueAt(linha, 0);

            UsuarioDAO dao = new UsuarioDAO();
            usuario = dao.pesquisarCodigo(codigo);
           

            O7AvisoExcluirUsuario tela = new O7AvisoExcluirUsuario(usuario, tbConsultarUsuario);
            tela.setVisible(true);
        }
    }
    
    private void btExcluirMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btExcluirMouseClicked
        
    excluirUsuario();
    }//GEN-LAST:event_btExcluirMouseClicked

    private void btAlterarSenhaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btAlterarSenhaMouseClicked
        int linha = tbConsultarUsuario.getSelectedRow();
        if(linha == -1){
            JOptionPane.showMessageDialog(rootPane, "Por favor, selecione um usuário");
        } else {
            Usuario usuario = new Usuario();
            int codigo = (int) tbConsultarUsuario.getValueAt(linha, 0);
            
            
            UsuarioDAO dao = new UsuarioDAO();
            usuario = dao.pesquisarCodigo(codigo);
            
            O9AvisoResetarSenha tela = new O9AvisoResetarSenha(usuario);
            tela.setVisible(true);
            
        }
    }//GEN-LAST:event_btAlterarSenhaMouseClicked

    private void btVerPerfilMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btVerPerfilMouseClicked
        // TODO add your handling code here:
        int linha = tbConsultarUsuario.getSelectedRow();
        if(linha == -1){
            JOptionPane.showMessageDialog(rootPane, "Por favor, selecione um usuário");
        } else {
            Usuario usuario = new Usuario();
            int codigo = (int) tbConsultarUsuario.getValueAt(linha, 0);
            
            
            UsuarioDAO dao = new UsuarioDAO();
            usuario = dao.pesquisarCodigo(codigo);
            
            O6TelaVerPerfilDeUsuario tela = new O6TelaVerPerfilDeUsuario(usuario);
            dispose();
            tela.setVisible(true);
        }
    }//GEN-LAST:event_btVerPerfilMouseClicked

    private void iconExcluirUsuarioMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_iconExcluirUsuarioMouseClicked
        // TODO add your handling code here:
        excluirUsuario();
    }//GEN-LAST:event_iconExcluirUsuarioMouseClicked

    private void jPanel7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel7MouseClicked
        // TODO add your handling code here:
        excluirUsuario();
    }//GEN-LAST:event_jPanel7MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                

}
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(O4TelaConsultarUsuarios.class  

.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } 

catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(O4TelaConsultarUsuarios.class  

.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } 

catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(O4TelaConsultarUsuarios.class  

.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } 

catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(O4TelaConsultarUsuarios.class  

.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new O4TelaConsultarUsuarios().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel btAlterarSenha;
    private javax.swing.JLabel btExcluir;
    private javax.swing.JLabel btVerPerfil;
    private javax.swing.JLabel iconExcluirUsuario;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tbConsultarUsuario;
    // End of variables declaration//GEN-END:variables

    public boolean isRespExcluir() {
        return respExcluir;
    }

    public void setRespExcluir(boolean respExcluir) {
        this.respExcluir = respExcluir;
    }

}
